package com.ivan.gunda.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Gunda_0_2 implements EntryPoint {

	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final IterationServiceAsync iterationService = GWT.create(IterationService.class);

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
	    final ListBox iterationsLB = new ListBox(false); 
	    iterationsLB.addItem("-- Select a Iteration --");
	    
	    RootPanel.get("gundaUI").add(iterationsLB);
	    
        iterationService.getIterations(new AsyncCallback<String[]>() {
            
            @Override
            public void onSuccess(String[] results) {
                for (int i=0; i < results.length; i++) {
                    iterationsLB.addItem(results[i]);
                }
                
            }
            
            @Override
            public void onFailure(Throwable caught) {
                handleError(caught);
                
            }
        });
	}
	
	protected void handleError(Throwable error) {
        Window.alert(error.getMessage()); 
    }
}
